<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">

<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>gamvas.AStarNode</title><link rel="stylesheet" type="text/css" href="../styles/main.css"><script language=JavaScript src="../javascript/main.js"></script><script language=JavaScript src="../javascript/prettify.js"></script><script language=JavaScript src="../javascript/searchdata.js"></script></head><body class="ContentPage" onLoad="NDOnLoad();prettyPrint();"><script language=JavaScript><!--
if (browserType) {document.write("<div class=" + browserType + ">");if (browserVer) {document.write("<div class=" + browserVer + ">"); }}// --></script>

<!--  Generated by Natural Docs, version 1.51 -->
<!--  http://www.naturaldocs.org  -->

<!-- saved from url=(0026)http://www.naturaldocs.org -->




<div id=Content><div class="CClass"><div class=CTopic id=MainTopic><h1 class=CTitle><a name="gamvas.AStarNode"></a>gamvas.<wbr>AStarNode</h1><div class=CBody><h4 class=CHeading>Description</h4><p>A base class for pathfinding nodes.&nbsp; You can override it with your own g() and h() functions</p><h4 class=CHeading>Constructor</h4><p>new gamvas.AStarNode(x, y, id);</p><h4 class=CHeading>Parameters</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>x, y</td><td class=CDLDescription>The position of the way point</td></tr><tr><td class=CDLEntry>id</td><td class=CDLDescription>A unique id for this node within the pathfinding system (optional, default: autogenerated)</td></tr></table><!--START_ND_SUMMARY--><div class=Summary><div class=STitle>Summary</div><div class=SBorder><table border=0 cellspacing=0 cellpadding=0 class=STable><tr class="SMain"><td class=SEntry><a href="#gamvas.AStarNode" >gamvas.<wbr>AStarNode</a></td><td class=SDescription>A base class for pathfinding nodes. </td></tr><tr class="SGroup SIndent1"><td class=SEntry><a href="#gamvas.AStarNode.Variables" >Variables</a></td><td class=SDescription></td></tr><tr class="SVariable SIndent2 SMarked"><td class=SEntry><a href="#gamvas.AStarNode.connected" >connected</a></td><td class=SDescription>A array holding the connected <a href="#gamvas.AStarNode" class=LClass id=link1 onMouseOver="ShowTip(event, 'tt1', 'link1')" onMouseOut="HideTip('tt1')">gamvas.AStarNode</a> elements</td></tr><tr class="SVariable SIndent2"><td class=SEntry><a href="#gamvas.AStarNode.position" id=link2 onMouseOver="ShowTip(event, 'tt2', 'link2')" onMouseOut="HideTip('tt2')">position</a></td><td class=SDescription>A <a href="gamvas-vector2d-js.html#gamvas.Vector2D" class=LClass id=link3 onMouseOver="ShowTip(event, 'tt3', 'link3')" onMouseOut="HideTip('tt3')">gamvas.Vector2D</a> holding the position of the node</td></tr><tr class="SGroup SIndent1"><td class=SEntry><a href="#gamvas.AStarNode.Functions" >Functions</a></td><td class=SDescription></td></tr><tr class="SFunction SIndent2 SMarked"><td class=SEntry><a href="#gamvas.AStarNode.g" id=link4 onMouseOver="ShowTip(event, 'tt4', 'link4')" onMouseOut="HideTip('tt4')">g</a></td><td class=SDescription>The path cost function, should return a value that represents how hard it is to reach the current node</td></tr><tr class="SFunction SIndent2"><td class=SEntry><a href="#gamvas.AStarNode.h" id=link5 onMouseOver="ShowTip(event, 'tt5', 'link5')" onMouseOut="HideTip('tt5')">h</a></td><td class=SDescription>The heuristic estimate</td></tr><tr class="SFunction SIndent2 SMarked"><td class=SEntry><a href="#gamvas.AStarNode.connect" id=link6 onMouseOver="ShowTip(event, 'tt6', 'link6')" onMouseOut="HideTip('tt6')">connect</a></td><td class=SDescription>Connect two nodes</td></tr></table></div></div><!--END_ND_SUMMARY--></div></div></div>

<div class="CGroup"><div class=CTopic><h3 class=CTitle><a name="gamvas.AStarNode.Variables"></a>Variables</h3></div></div>

<div class="CVariable"><div class=CTopic><h3 class=CTitle><a name="gamvas.AStarNode.connected"></a>connected</h3><div class=CBody><p>A array holding the connected <a href="#gamvas.AStarNode" class=LClass id=link7 onMouseOver="ShowTip(event, 'tt1', 'link7')" onMouseOut="HideTip('tt1')">gamvas.AStarNode</a> elements</p></div></div></div>

<div class="CVariable"><div class=CTopic><h3 class=CTitle><a name="gamvas.AStarNode.position"></a>position</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "colspan=2>create: function(</td></tr><tr><td>&nbsp;&nbsp;&nbsp;</td><td class="PParameter  prettyprint " nowrap width=100%>x,</td></tr><tr><td>&nbsp;&nbsp;&nbsp;</td><td class="PParameter  prettyprint " nowrap width=100%>y,</td></tr><tr><td>&nbsp;&nbsp;&nbsp;</td><td class="PParameter  prettyprint " nowrap width=100%>id</td></tr><tr><td class="PAfterParameters  prettyprint "colspan=2>) { this.connected = new Array(); this.position = new gamvas.Vector2D(x, y); (id) ? this.id = id : this.id = this.position.x+'_'+this.position.y; }</td></tr></table></td></tr></table></blockquote><p>A <a href="gamvas-vector2d-js.html#gamvas.Vector2D" class=LClass id=link8 onMouseOver="ShowTip(event, 'tt3', 'link8')" onMouseOut="HideTip('tt3')">gamvas.Vector2D</a> holding the position of the node</p></div></div></div>

<div class="CGroup"><div class=CTopic><h3 class=CTitle><a name="gamvas.AStarNode.Functions"></a>Functions</h3></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="gamvas.AStarNode.g"></a>g</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>g: function(</td><td class="PParameter  prettyprint " nowrap>n</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote><p>The path cost function, should return a value that represents how hard it is to reach the current node</p><h4 class=CHeading>Parameters</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>n</td><td class=CDLDescription>The node we are coming from</td></tr></table><h4 class=CHeading>Returns</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>Negative values</td><td class=CDLDescription>Current node can not be reached from node n</td></tr><tr><td class=CDLEntry>Positive values</td><td class=CDLDescription>Representing the costs reaching the current node from node n</td></tr></table><h4 class=CHeading>Example</h4><blockquote><pre>gamvas.AStarGridNode = gamvas.AStarNode.extend({
   create: function(x, y, id) {
      this._super(x, y, id);
   },
   g: function(n) {
      // get height difference
      var diff = Math.abs(this.position.y-n.position.y);
      if (diff &gt; 10) {
         return -1; // we can not step over 10 in height
      }
      // give it some weight so the higher the differnce, the more unlikely it is, the path will walk over it
      return diff * diff;
   }
});</pre></blockquote></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="gamvas.AStarNode.h"></a>h</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>h: function(</td><td class="PParameter  prettyprint " nowrap>n,</td></tr><tr><td></td><td class="PParameter  prettyprint " nowrap>t</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote><p>The heuristic estimate</p><h4 class=CHeading>Parameters</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>n</td><td class=CDLDescription>The node we are coming from</td></tr><tr><td class=CDLEntry>t</td><td class=CDLDescription>The target of the current path find</td></tr></table><h4 class=CHeading>Returns</h4><p>The estimated cost to the path target</p><h4 class=CHeading>Example</h4><p>This is the standard implementation, which returns the distance to the target.</p><p>If you have more information, like for example number of opponents between target and current position, you could return a higher value if too many opponants are between target and current position, so the algorithm will try to avoid running directly through hordes of monsters.</p><blockquote><pre>gamvas.AStarGridNode = gamvas.AStarNode.extend({
   create: function(x, y, id) {
      this._super(x, y, id);
   },
   h: function(n, t) {
      var dif = this.position.difference(t.position);
      return dif.length();
   }
});</pre></blockquote></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="gamvas.AStarNode.connect"></a>connect</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>connect: function(</td><td class="PParameter  prettyprint " nowrap>n,</td></tr><tr><td></td><td class="PParameter  prettyprint " nowrap>auto</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote><p>Connect two nodes</p><h4 class=CHeading>Parameters</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>n</td><td class=CDLDescription>The node to connect to</td></tr><tr><td class=CDLEntry>auto</td><td class=CDLDescription>true/false if automatically set up a bidirectional connection (optional, default: true)</td></tr></table></div></div></div>

</div><!--Content-->


<div id=Footer><a href="http://www.naturaldocs.org">Generated by Natural Docs</a></div><!--Footer-->


<div id=Menu><div class=MEntry><div class=MFile><a href="gamvas-base-js.html">gamvas</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-actor-js.html">gamvas.<wbr>Actor</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-actorstate-js.html">gamvas.<wbr>ActorState</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-animation-js.html">gamvas.<wbr>Animation</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-astar-js.html">gamvas.<wbr>AStar</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-astargrid-js.html">gamvas.<wbr>AStarGrid</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-astargridnode-js.html">gamvas.<wbr>AStarGridNode</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-astarmap-js.html">gamvas.<wbr>AStarMap</a></div></div><div class=MEntry><div class=MFile id=MSelected>gamvas.<wbr>AStarNode</div></div><div class=MEntry><div class=MFile><a href="gamvas-camera-js.html">gamvas.<wbr>Camera</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-class-js.html">gamvas.<wbr>Class</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-config-js.html">gamvas.<wbr>config</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-dom-js.html">gamvas.dom</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-event-js.html">gamvas.<wbr>event</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-image-js.html">gamvas.<wbr>Image</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-key-js.html">gamvas.key</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-math-js.html">gamvas.math</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-mouse-js.html">gamvas.<wbr>mouse</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-particleemitter-js.html">gamvas.<wbr>ParticleEmitter</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-physics-js.html">gamvas.<wbr>physics</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-physics-userdata-js.html">gamvas.<wbr>physics.<wbr>UserData</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-rect-js.html">gamvas.Rect</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-resource-js.html">gamvas.<wbr>Resource</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-screen-js.html">gamvas.<wbr>screen</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-sound-js.html">gamvas.<wbr>Sound</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-state-js.html">gamvas.<wbr>state</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-state-state-js.html">gamvas.<wbr>State</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-timer-js.html">gamvas.<wbr>timer</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-vector2d-js.html">gamvas.<wbr>Vector2D</a></div></div><div class=MEntry><div class=MGroup><a href="javascript:ToggleMenu('MGroupContent1')">Index</a><div class=MGroupContent id=MGroupContent1><div class=MEntry><div class=MIndex><a href="../index/General.html">Everything</a></div></div><div class=MEntry><div class=MIndex><a href="../index/Classes.html">Classes</a></div></div><div class=MEntry><div class=MIndex><a href="../index/Functions.html">Functions</a></div></div><div class=MEntry><div class=MIndex><a href="../index/Macros.html">Macros</a></div></div><div class=MEntry><div class=MIndex><a href="../index/Variables.html">Variables</a></div></div></div></div></div><script type="text/javascript"><!--
var searchPanel = new SearchPanel("searchPanel", "HTML", "../search");
--></script><div id=MSearchPanel class=MSearchPanelInactive><input type=text id=MSearchField value=Search onFocus="searchPanel.OnSearchFieldFocus(true)" onBlur="searchPanel.OnSearchFieldFocus(false)" onKeyUp="searchPanel.OnSearchFieldChange()"><select id=MSearchType onFocus="searchPanel.OnSearchTypeFocus(true)" onBlur="searchPanel.OnSearchTypeFocus(false)" onChange="searchPanel.OnSearchTypeChange()"><option  id=MSearchEverything selected value="General">Everything</option><option value="Classes">Classes</option><option value="Functions">Functions</option><option value="Macros">Macros</option><option value="Variables">Variables</option></select></div><script language=JavaScript><!--
HideAllBut([], 2);// --></script></div><!--Menu-->



<!--START_ND_TOOLTIPS-->
<div class=CToolTip id="tt1"><div class=CClass>A base class for pathfinding nodes. </div></div><div class=CToolTip id="tt2"><div class=CVariable><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "colspan=2>create: function(</td></tr><tr><td>&nbsp;&nbsp;&nbsp;</td><td class="PParameter  prettyprint " nowrap width=100%>x,</td></tr><tr><td>&nbsp;&nbsp;&nbsp;</td><td class="PParameter  prettyprint " nowrap width=100%>y,</td></tr><tr><td>&nbsp;&nbsp;&nbsp;</td><td class="PParameter  prettyprint " nowrap width=100%>id</td></tr><tr><td class="PAfterParameters  prettyprint "colspan=2>) { this.connected = new Array(); this.position = new gamvas.Vector2D(x, y); (id) ? this.id = id : this.id = this.position.x+'_'+this.position.y; }</td></tr></table></td></tr></table></blockquote>A gamvas.Vector2D holding the position of the node</div></div><div class=CToolTip id="tt3"><div class=CClass>A 2D vector class</div></div><div class=CToolTip id="tt4"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>g: function(</td><td class="PParameter  prettyprint " nowrap>n</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote>The path cost function, should return a value that represents how hard it is to reach the current node</div></div><div class=CToolTip id="tt5"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>h: function(</td><td class="PParameter  prettyprint " nowrap>n,</td></tr><tr><td></td><td class="PParameter  prettyprint " nowrap>t</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote>The heuristic estimate</div></div><div class=CToolTip id="tt6"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>connect: function(</td><td class="PParameter  prettyprint " nowrap>n,</td></tr><tr><td></td><td class="PParameter  prettyprint " nowrap>auto</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote>Connect two nodes</div></div><!--END_ND_TOOLTIPS-->




<div id=MSearchResultsWindow><iframe src="" frameborder=0 name=MSearchResults id=MSearchResults></iframe><a href="javascript:searchPanel.CloseResultsWindow()" id=MSearchResultsWindowClose>Close</a></div>


<script language=JavaScript><!--
if (browserType) {if (browserVer) {document.write("</div>"); }document.write("</div>");}// --></script></body></html>